package com.xy.template.constant;

public class ColumnTypeConvert {
    /**
     * 将获取数据库类型转化为java类型
     *
     * @param dbTypeName 实际的数据库类型
     * @return
     */
    public static String toJavaType(String dbTypeName, int scale) {
        String javaType = null;
        switch (dbTypeName.toUpperCase()) {
            case "NUMBER":
                if (scale > 0) {
                    javaType = "BigDecimal";
                } else {
                    javaType = "Long";
                }
                break;
            case "VARCHAR":
                javaType = "String";
                break;
            case "JSON":
                javaType = "String";
                break;
            case "NVARCHAR":
                javaType = "String";
                break;
            case "BIGINT":
                javaType = "Long";
                break;
            case "INT8":
                javaType = "Long";
                break;
            case "TINYINT":
                javaType = "Integer";
                break;
            case "INT":
                javaType = "Integer";
                break;
            case "INT4":
                javaType = "Integer";
                break;
            case "DATETIME":
                javaType = "Date";
                break;
            case "DATETIME2":
                javaType = "Date";
                break;
            case "DATE":
                javaType = "Date";
                break;
            case "TIMESTAMP":
                javaType = "Date";
                break;
            case "NUMERIC":
                javaType = "BigDecimal";
                break;
            case "DECIMAL":
                javaType = "BigDecimal";
                break;
            case "FLOAT":
                javaType = "BigDecimal";
                break;
            case "DOUBlE":
                javaType = "BigDecimal";
                break;
            default:
                javaType = "String";
                break;
        }
//        System.out.println("类型转换" + dbTypeName + " -----  " + javaType);
        return javaType;
    }
}
